var pageList = [15,20,25,30,40,50];
//$(function(){
	//if(getCookie('cs-skin')) {
	//	var themeName = getCookie('cs-skin');
	//	changeTheme(themeName);
	//}
//})
$.fn.panel.defaults.loadingMessage = '数据加载中，请稍候....';
$.fn.datagrid.defaults.loadMsg = '数据加载中，请稍候....';
$.ajaxSetup({
	//contentType : "application/x-www-form-urlencoded;charset=utf-8",
	complete : function(xhr) {
		if (xhr.status == 911) {
			window.top.$.messager.alert('温馨提示', '由于您长时间未操作或者网络断开导致操作失败，请您重新登录！', '', function(){
				location.replace("toLogin.do");
			});
			return;
		} else if(xhr.status == 912){
			window.top.$.messager.alert('温馨提示', '您没有权限操作！');
			return;
		}
	}
});
function changeTheme(themeName){
	var url = $('#easyuiTheme').attr('href');
	var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
	$('#easyuiTheme').attr('href', href);
	var $iframe = $('iframe');
	if ($iframe.length > 0) {
		for ( var i = 0; i < $iframe.length; i++) {
	      var ifr = $iframe[i];
          $(ifr).contents().find('#easyuiTheme').attr('href', href);
        }
	}
}

function setCookie(name,value) {//两个参数，一个是cookie的名子，一个是值
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(name) {//取cookies函数        
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}


/**
 * 
 */
function showWindow(title, href, width, height, modal, minimizable, maximizable) {
	var openWin = top.$('<div id="myWinId" class="easyui-window" closed="true"></div>').appendTo(window.top.document.body);
	//var openWin = $('<div id="myWinId" class="easyui-window" closed="true"></div>').appendTo(document.body);
	openWin.window({
        title: title,
        width: width === undefined ? 600 : width,
        height: height === undefined ? 400 : height,
        content: '<iframe scrolling="no" frameborder="0"  src="' + href + '" style="width:100%;height:99%;"></iframe>',
        //href: href === undefined ? null : href,
        modal: modal === undefined ? true : modal,
        minimizable: minimizable === undefined ? false : minimizable,
        maximizable: maximizable === undefined ? false : maximizable,
        shadow: false,
        inline: false,
        cache: false,
        closed: false,
        collapsible: false,
        resizable: false,
        loadingMessage: '正在加载数据，请稍等片刻......',
        onClose : function(){ 
        	openWin.window("destroy");
        } 
    });
}

/**
 * 关闭弹出框
 */
function closeWindow() {
	top.$('#myWinId').window('close');
	//$('#myWinId').window('close');
}

function showAlert(title, msg){
	window.top.$.messager.alert(title, msg);
}
function showAlertMsg(){
	window.top.$.messager.alert("提示信息", "请选择一条记录");
}
function showDeleteAlert(){
	window.top.$.messager.alert("提示信息", "请选择删除记录");
}
function showMsg(title, msg, isAlert) {
	if (isAlert !== undefined && isAlert) {
		window.top.$.messager.alert(title, msg);
	} else {
		window.top.$.messager.show({
	    	 title: title,
	    	 msg: msg,
	    	 showType: 'show'
	     });
	}
}
function showSuccessAlert(msg){
	if(msg != undefined && msg.length >0){
		window.top.$.messager.alert('温馨提示', msg);
	}else{
		window.top.$.messager.alert('温馨提示', '操作成功！');
	}
}
function showFailAlert(msg){
	if(msg != undefined && msg.length >0){
		window.top.$.messager.alert('温馨提示', msg);
	}else{
		window.top.$.messager.alert('温馨提示', '操作失败！');
	}
}

function showFailAlert2(xhr){
	if(xhr.status != 911&&xhr.status!= 912){
		  showFailAlert()
	}
}
function showSuccessMsg(){
	showMsg('温馨提示', '操作成功！');
}
function showFailMsg(){
	showMsg('温馨提示', '操作失败！');
}
function deleteConfirm(callback) {
    return showConfirm('温馨提示', '确定要删除吗?', callback);
}

function showConfirm(title, msg, callback) {
	window.top.$.messager.confirm(title, msg, function (r) {
        if (r) {
            if (jQuery.isFunction(callback))
                callback.call();
        }
    });
}

function showProcess(isShow, title, msg) {
    if (!isShow) {
    	window.top.$.messager.progress('close');
        return;
    }
    var win = window.top.$.messager.progress({
        title: title,
        msg: msg
    });
}

function getSelectedRows(dataTableId){
	var rows = $('#' + dataTableId).datagrid('getSelections');
	return rows;
}

function reloadTable(dataTableId) {
    $('#' + dataTableId).datagrid('reload');
}